/**
 * 
 */
package code.google.qinglan.xml;

import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

/**
 * 读取xml文件类
 * 
 * @author wxq
 * 
 */
public class DocHelper {

	private DocumentBuilderFactory docfac;
	private DocumentBuilder dombuilder;

	/**
	 * 
	 */
	public DocHelper() {
		this.docfac = DocumentBuilderFactory.newInstance();
		try {
			this.dombuilder = docfac.newDocumentBuilder();
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 读取指定路径的xml文档
	 * 
	 * @param filePath
	 *            xml文档路径
	 * @return Document
	 */
	public Document readDocument(String filePath) {
		try {
			return this.dombuilder.parse(filePath);
		} catch (SAXException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}
